<?php
/**
 * @todo    线上家博会controller
 */
namespace Home\Controller;
use Home\Controller;
class OnlineController extends HomeController {
    
    /**
     * @todo    首页
     */
    public function index(){

        // 品类图标
        $icon = array(
            '23' => 18,
            '22' => 19,
            '21' => 33,
            '20' => 17,
            '19' => 16,
            '18' => 15,
            '17' => 12,
            '16' => 14,
            '15' => 11,
            '14' => 1,
            '13' => 4,
            '12' => 2,
            '11' => 10,
            '10' => 3,
            '9' => 5,
            '8' => 6,
            '7' => 9,
            '6' => 8,
            '5' => 7,
            '4' => 21,
            '3' => 22,
            '2' => 20,
            '1' => 23,
        );
        $icon_one = array(
            '1' => 29,
            '2' => 31,
            '3' => 35,
            '4' => 34,
            '5' => 37,
        );
        $obj = D('Online');
        // 展馆＋品类
        $zone_category = $obj->getZoneCategory();
        // 功能区
        $page_list = $obj->getPageList();
        // 当前线上家博会id
        $activity_id = $obj->getOnlineID();
        $this->assign('zone_category', $zone_category);
        $this->assign('icon', $icon);
        $this->assign('icon_one', $icon_one);
        $this->assign('activity_id', $activity_id);
        $this->assign('page_list', $page_list);
        $this->display();
    }
    
    /**
     * @todo    展馆品类聚合页
     */
    public function zoneCategory(){
        
        $category_id = (int)I('category_id');
        // 展馆－品类－店铺
        $list = D('Online')->getZoneCategoryShop();
        // 爆款获取
        $hot_list = D('Shop')->getGoodsList(array('position' => 2097152,'status' => 1));
        // 获取品类信息
        $category_info = ($category_id > 0)? D('Online')->getCategoryInfo($category_id) : null ;
        //dump($category_info);die;
        //dump($hot_list);die;
        $this->assign('zone_category_list', json_encode($list));
        $this->assign('category_info', $category_info);
        $this->assign('hot_list', $hot_list);
        $this->display('list');
    }
    
    /**
     * @todo    店铺详细页面
     */
    public function shop(){
        
        $shop_id = (int)I('shop_id');
        if($shop_id == 0){
            $this->error('参数错误');
        }
        $obj = D('Online');
        // 我的收藏
        $my_collection = $obj->getMyCollection('online_goods_id');
        $my_collection_ids = ($my_collection)? implode(',',array_column($my_collection, 'online_goods_id')) : array() ;
        // 展馆－品类－店铺
        $list = $obj->getZoneCategoryShop();
        // 店铺商品
        $shop_info = $obj->getShopInfo($shop_id);
        $goods_list = $obj->getGoodsList($shop_id);
        //dump($goods_list);die;
        $this->assign('zone_category_list', json_encode($list));
        $this->assign('shop_info', $shop_info);
        $this->assign('goods_list', $goods_list);
        $this->assign('my_collection_ids', $my_collection_ids);
        $this->display('shop');
    }
    
    /**
     * @todo    线上家博会店铺页面
     */
    public function onlineShop(){
        
        $shop_id = (int)I('shop_id');
        if($shop_id == 0){
            $this->error('参数错误');
        }
        $obj = D('Online');
        // 获取店铺信息
        $shop_info = $obj->getShopInfo($shop_id);
        // 获取店铺商品
        $goods_list = $obj->getGoodsList($shop_id);

        $this->assign('shop_info', $shop_info);
        $this->assign('goods_list', $goods_list);
        $this->display();
    }
    
    /**
     * @todo    功能区详细页面
     */
    public function onePage(){
        
        $id = (int)I('id');
        if($id == 0){
            $this->error('参数错误');
        }
        $info = D('Online')->getOnePageInfo($id);
        $this->assign('info', $info);
        $this->display('one_page');
        
    }
    
    /**
     * @todo    我的收藏列表
     */
    public function myCollection(){
        
        if(UID == 0){
            $this->redirect('Customer/login');
        }
        $list = D('Online')->getMyCollection();
        $this->assign('list', $list);
        $this->display('favour');
    }

    /**
     * @todo    添加收藏
     */
    public function collectionAdd(){
    
        $shop_id = (int)I('shop_id');
        $goods_id = (int)I('goods_id');
        if($goods_id == 0 || $shop_id == 0){
            $this->error('参数错误');
        }
        if(UID > 0){
            // 收藏
            if(D('Online')->collectionAdd($goods_id)){
                $this->redirect('Online/shop', array('shop_id' => $shop_id));
            }else{
                $this->error('服务器繁忙，请稍后再试！');
            }
        }else{
            $this->redirect('Customer/login');
        }
    }
    
    /**
     * @todo    删除收藏
     */
    public function collectionDel(){
        $id = (int)I('id');
        if($id == 0){
            $this->error('参数错误');
        }
        M('online_my_collection')->where(array('collection_id' => $id))->delete();
        $this->redirect('Online/myCollection');
    }
    
}